﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Artech.Core
{
    public static class StatefulEntryCollectionExtensions
    {
        public static IEnumerable<T> GetChanges<T>(this StatefulEntryCollection<T> entries) where T : StatefulEntry
        {
            foreach (T entry in entries.Where(item => item.State == EntryState.Added || item.State == EntryState.Modified || item.State == EntryState.Deleted).ToArray())
            {
                yield return entry;
            }
        }

        public static IEnumerable<T> GetChanges<T>(this StatefulEntryCollection<T> entries, EntryState state) where T : StatefulEntry
        {
            foreach (T entry in entries.Where(item => item.State == state))
            {
                yield return entry;
            } 
        }

        public static IEnumerable<T> GetAddedEntries<T>(this StatefulEntryCollection<T> entries) where T : StatefulEntry
        {
            return GetChanges(entries, EntryState.Added);
        }

        public static IEnumerable<T> GetModifiedEntries<T>(this StatefulEntryCollection<T> entries) where T : StatefulEntry
        {
            return GetChanges(entries, EntryState.Modified);
        }

        public static IEnumerable<T> GetDeletedEntries<T>(this StatefulEntryCollection<T> entries) where T : StatefulEntry
        {
            return GetChanges(entries, EntryState.Deleted);
        }
    }
}
